import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
// @ts-ignore
import path from "path";

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [vue()],
  base: "./", //打包路径
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "./src"), //设置别名
      "~": path.resolve(__dirname, "/src/components"),
    },
  },
  server: {
    port: 4000, //启动端口
    open: true,
    host: "0.0.0.0",
    proxy: {
      // 选项写法
      // "/api": "http://162.14.98.165:3000", //代理网址
      "/api": {
        target: "http://localhost:3000",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/,''), // 不可以省略rewrite
      }
    },

    cors: true,
  },
  build: {
    target: ['edge90', 'chrome90', 'firefox90', 'safari15']
  },
  css: {
    postcss: {
      plugins: [
        {
          postcssPlugin: 'internal:charset-removal',
          AtRule: {
            charset: (atRule) => {
              if (atRule.name === 'charset') {
                atRule.remove();
              }
            }
          }
        }
      ]
    }
  }
});
